<!DOCTYPE html>
<html>
<head>
<title>选择</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
{webcontrol type='LoadJsCss' src="Resource/Script/jquery.1.9.1.js"}
{webcontrol type='LoadJsCss' src="Resource/Script/select2/select2.js"}
{webcontrol type='LoadJsCss' src="Resource/Script/select2/select2.css"}
{webcontrol type='LoadJsCss' src="Resource/bootstrap/bootstrap/css/bootstrap.css"}
{webcontrol type='LoadJsCss' src="Resource/Css/scrollbar.css"}
</head>

<script type="text/javascript">
var controller = '{$smarty.get.controller}';
var index = '{$smarty.get.index}';
var ids=parent.$('[name="Madan[]"]').eq(index).val();
{literal}
$(function(){
    //初始化显示的数据
    var c_ids = ids.split(',');
    //选中之前选择的数据，
    $('[name="docheck[]"]').each(function(){
        if(c_ids.indexOf(this.value)>=0){
            $(this).prop('checked',true);
        }
    });

    $('.select2').select2();

    //全选/反选
    $('[name="sel"]').click(function(){
        $('[name="docheck[]"]').prop('checked',this.checked);
        cc();
    });

    //ok
    $('#ok').click(function(){
        var che_data = getSelData();
        // if(!che_data.cId){
        //     parent.layer.alert("先选择要出库的码单信息");
        // }

        //返回已选择的数据
        var obj = {'cId':che_data.cId,'cnt':che_data.cnt,'cntJuan':che_data.cntJuan,'cntL':che_data.cntL,'cntDz':che_data.cntDz,'cntTongzi':che_data.cntTongzi};
        parent.layer.callback(index,obj);
        parent.tb_remove();
    });

    //back
    $('#back').click(function(){
        parent.tb_remove();
    });
    cc();
});

function cc(){
     var tz = 0;
     var mz = 0;
     $('[name="docheck[]"]').each(function(){
         if($(this).prop('checked')==true){
            tz+=parseFloat($(this).attr('cntTongzi'))||0;
            mz+=parseFloat($(this).attr('cnt'))||0;
         }
    });
    $('#tongzi').html(tz);
    mz = parseFloat(mz).toFixed(2);
    $('#mz').html(mz);
}

function getSelData(){
    var data = [];
    var cnt = 0;
    var cntL = 0;
    var cntDz = 0;//定重
    var cntTongzi=0;//筒子数
    var i=0;
    $('[name="docheck[]"]:checked').each(function(){
        if(!this.disabled){
            data.push(this.value);
            var t_cnt = parseFloat($(this).attr('cnt'))||0;
            var t_cntL = parseFloat($(this).attr('cntL'))||0;
            var t_cntDz = parseFloat($(this).attr('cntDz'))||0;
            var tongzi = parseFloat($(this).attr('cntTongzi'))||0;
            cnt+=t_cnt;
            cntL+=t_cntL;
            cntDz+=t_cntDz;
            cntTongzi+=tongzi;
            i++;
        }
    });

    return {'cId':data.join(','),'cnt':cnt.toFixed(6),'cntJuan':i,'cntL':cntL,'cntDz':cntDz,'cntTongzi':cntTongzi};
}
</script>
<style type="text/css">
    .bottom-5{margin-bottom: 5px;}
</style>
{/literal}
<body>
<div class='container-fluid'>
<form name="form1" id="form1" action="{url controller=$smarty.get.controller action='Peihuo'}" method="post">
    <input type="hidden" name="id" id="id" value="{$Peihuo.id}">
    <!-- 校验码单 -->
    <div class="row">
        <div class="col-xs-12">
            <div class="form-group">
                <pre>
                产品信息: {$gang.vatNum} 投料数：{$gang.cntPlanTouliao}Kg 筒子数：<span id="tongzi"></span>只 出库数：<span id="mz"></span>kg {$gang.OrdWare.color} {$gang.OrdWare.colorNum}
                </pre>
            </div>


        </div>
    </div>

    <div class="form-contrl"><input type="checkbox" name='sel' value="">全选/反选</div>
  <!--   <div class="row" style="margin-top:5px;">
        <div class="col-xs-2">
        <p class="bg-success"><strong>{$key}</strong></p>
        </div>
    </div> -->
    <div class="row">
    {foreach from=$res item=item key=key}
        <div class="col-xs-4">
            <div class="form-control bottom-5">
                <p {if $item.disabled}class="text-danger"{/if} title='定重{$item.dingzhong},check_main.id={$item.id}'>
                <b >{$item.checkID}</b># 毛重{$item.weight}, 筒子数{$item.cntTongzi},件号{$item.checkID}&nbsp;&nbsp;
                <input type="checkbox" name='docheck[]' value= '{$item.madanId}' cnt='{$item.weight}' cntL='{$item.length}' cntDz='{$item.dingzhong}' cntTongzi='{$item.cntTongzi}' onclick="cc()" style="width:15px;height:15px;" {if $item.checked}checked{/if} {if $item.disabled}disabled{/if}>
                </p>
            </div>
        </div>
    {/foreach}
    </div>

    <!-- 按钮区 -->
    <div class="form-group col-xs-12">
        <div class="text-center">
            <input class="btn btn-default" type="button" id="ok" name="ok" value=" 确定 ">
            <input class="btn btn-warning" type="button" id="back" name="back" value=" 返 回 ">
        </div>
    </div>
</form>
</div>
</body>
</html>